package com.fast.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * SpringAop
 * 
 * @author Tonny Luo
 *
 */
@Component
@Aspect
public class SpringAop {

	private final static Logger log = LoggerFactory.getLogger(SpringAop.class);
	private long start = 0L;

	@Around("execution(* com.fast.service..*Service*.*(..))")
	public Object around(ProceedingJoinPoint pjp) throws Throwable {
		before();
		Object result = pjp.proceed();
		after(pjp);
		return result;
	}

	public void before() {
		start = System.currentTimeMillis();
	}

	public void after(ProceedingJoinPoint pjp) {
		String cls = pjp.getTarget().getClass().getCanonicalName();
		String methodName = pjp.getSignature().getName();
		log.info("[{} -> {}]执行结束,执行耗时{}秒.", cls, methodName, ((System.currentTimeMillis() - start) / 1000f));
	}
}